<?
include_once("/var/www/html/new/d/common/header.html");
include_once("/var/www/html/new/d/common/left.html");
include_once('/var/www/html/new/d/class/MemberAccount.class.php');
include_once("/var/www/html/new/d/class/Member.php");
include_once("/var/www/html/new/d/class/ProOrder.php");

$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));


// 资金预警阀值
$cordon = pft\Member\MemberAccount::getBankroll($_SESSION['sid'])/100;

$hour=date("H");
if($hour>=6&&$hour<=12){
	$hourT="上午";
}elseif($hour>12&&$hour<=14){
	$hourT="中午";
}elseif($hour>14&&$hour<=18){
	$hourT="下午";
}else{
	$hourT="晚上";
}
$memberID=$_SESSION['sid'];
$m=new Member($s,$memberID);
$m_info=$m->info();
$v['pnums']=$m->pronum();
$v['money']=$m->money()/100;
$v['hourT']=$hourT;

function sortByOrder($a,$b){
	if($a['order']>$b['order']) return -1;
	if($a['order']<$b['order']) return 1;
	return 0;
}
if($_SESSION['dtype']!=5){
	$object=saleProOrderObject($memberID,$s,$m_info['dtype'],$_SESSION['saccount']);
//	 管理员获取当天
    $weekSales= ($m_info['dtype']==9)?$object->daySaleOrders():$object->weekSaleOrders();
	$out=uasort($weekSales,"sortByOrder");
	if(isset($_REQUEST['d'])){
		switch($_REQUEST['d']){
			case 'today':
				$dayFlag = '今日';
				$btime = date('Y-m-d');
				$etime = $btime;
				$daySales = $object->_dateOrdersCount($btime,$etime);
				break;
			case 'yesterday':
				$dayFlag = '昨天';
				$btime = date('Y-m-d',time()-24*3600);
				$etime = $btime;
				$daySales = $object->_dateOrdersCount($btime,$etime);
				break;
			case 'week':
				$dayFlag = '本周';
				$btime = date('Y-m-d',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'))+7*24*3600);
				$etime = date('Y-m-d');
				$daySales = $object->_dateOrdersCount($btime,$etime);
				break;
			case 'lastWeek':
				$dayFlag = '上周';
				$btime = date('Y-m-d',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
				$etime = date('Y-m-d',strtotime($btime)+6*24*3600);
				$daySales = $object->_dateOrdersCount($btime,$etime);
				break;
			case 'mon':
				$dayFlag = '本月';
				$btime = date('Y-m-d',mktime(0,0,0,date('m'),1,date('Y')));
				$etime = date('Y-m-d');
				$daySales = $object->_dateOrdersCount($btime,$etime);
				break;
			case 'lastMon':
				$dayFlag = '上月';
				// 获取下个月
				$nowMon = date('n');
				$nowYear = date('Y');
				$lastMon = $nowMon - 1;
				if($lastMon < 1)
				{
					$lastMon = 12;
					$nowYear = $nowYear - 1;
				}
				if($lastMon > 12){
					$lastMon = 1;
					$nowYear = $nowYear + 1;
				}
				$btime = $nowYear.'-'.$lastMon.'-1';
				$etime = $nowYear.'-'.$lastMon.'-'.date('t',strtotime($date));
				echo $bdate,$edate;
				$daySales = $object->_dateOrdersCount($btime,$etime);
				break;
			default:
				$daySales = $object->_dateOrdersCount();
				break;
		}
	}else{
		$dayFlag = '今日';
		$btime = date('Y-m-d');
		$etime = $btime;
		$daySales = $object->_dateOrdersCount();
	}
}
if($m_info['dtype']==0){
	$v['uppronum']=$m->upProNum();
	$v['downpronum']=$m->downProNum();
	$v['fxnum']=$m->distributorNum();
	$v['supplynum']=$m->supplierNum();
}

$debug = $_GET["debug"];
if(!isset($debug)){
	include('/var/www/html/new/d/module/wxh/tpl/home.tpl');
}else{
	include('/var/www/html/new/d/tpl/home_today.tpl');
}
//include("tpl/home.tpl");
include("/var/www/html/new/d/common/footer.html");
?>